Skip to content

Make resume method async#56

Open
pdufour wants to merge 6 commits intoDioxusLabs:mainfrom
pdufour:paul.dufour/make-resume-async
Open

Make resume method async#56
pdufour wants to merge 6 commits intoDioxusLabs:mainfrom
pdufour:paul.dufour/make-resume-async

Conversation

@pdufour
Copy link
Copy Markdown

@pdufour pdufour commented Mar 30, 2026

As discussed here DioxusLabs/blitz#160 (comment) the resume method needs to be async for WASM compatibility. This changes the API to an async one.

I recommend looking at the PR with ignore whitespace on https://github.com/DioxusLabs/anyrender/pull/56/changes#diff-d59986e672b1ca00b645e906e7d8018fd74f9ddc5b38f22e94c5da0f5d9dd679?w=1

Some notes:

  • This requires the callers to implement block_on now. Another option would be to add a resume_sync method that does this, let me know what you prefer.
  • I'm not sure if it was intended but I only see 0.7.0 on main, is 0.8.0 supposed to be pushed?

Test plan

Test bunnymark

  • cargo run -p bunnymark
  • See that the app runs successfully

Test wasm

  • Run the demo in examples/wasm
export RUSTUP_TOOLCHAIN=1.92
wasm-pack build examples/wasm --target web --out-dir src/pkg
cargo run -p anyrender_wasm_example --bin serve -- 8080

@nicoburns
Copy link
Copy Markdown
Member

I'm not sure if it was intended but I only see 0.7.0 on main, is 0.8.0 supposed to be pushed?

Yes, sorry about that! Pushed.

Copy link
Copy Markdown
Member

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but I would like to see this actually running on WASM before merging. In particular, the reason for making this method async is that (AFAIK) polling the surface aquisition future with pollster won't work on WASM (because the future is comes from the JS runtime which can't make progress while our wasm code is blocking), and that we need to spawn it with wasm_bindgen_futures, and then actually await and then handle the result in async manner.

@pdufour pdufour force-pushed the paul.dufour/make-resume-async branch from 1a69099 to 96c5664 Compare March 30, 2026 14:48
@pdufour
Copy link
Copy Markdown
Author

pdufour commented Mar 30, 2026

@nicoburns thanks! added a wasm example to examples/wasm with a README on how to run it.

Video demo:

async-demo.mp4

@pdufour
Copy link
Copy Markdown
Author

pdufour commented Mar 30, 2026

You are correct in that the code on main does not work on wasm:

image

@pdufour
Copy link
Copy Markdown
Author

pdufour commented Apr 12, 2026

@nicoburns got any upcoming time to look at this? thanks!

Copy link
Copy Markdown
Member

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this does make the resume method async, but I don't think it's going to work with the WindowRenderer actually running with a Winit application/window. This is because the async method holds a mutable reference to self, and I think that's going to run into borrow-checking issues.

I think perhaps a channel might by the best way around this. When the async surface creation completes it could send it back to the WindowRenderer through a channel, resolve the future, and then the setup could be completed on the next call to render.

We might also consider having resume take a callback to call once the surface is ready (instead of making it an async function). Then we could keep all the future/async machinery inside the WindowRenderer (the caller would then generate a Winit event (e.g. request_redraw or a custom event) when the callback is called).

@nicoburns
Copy link
Copy Markdown
Member

Let's try and get a WASM example running with Winit-based event loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants